package com.junchenrobot.mes.dao;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.junchenrobot.mes.domain.Winder;
import com.junchenrobot.mes.domain.WinderTask;
import com.junchenrobot.mes.domain.WinderTime;
import com.junchenrobot.mes.mapper.WinderMapper;
import com.junchenrobot.mes.mapper.WinderTimeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * 卷绕机络筒后停留时间Dao
 * 包含卷绕机络筒后停留时间数据库操作
 */
@Component
public class WinderTimeDao {

    @Autowired
    private WinderTimeMapper winderTimeMapper;

    /**
    * 修改卷绕机络筒后停留时间
     */
    public void updateTaskByTaskCode(Long id, Long time,String variety,String modelNumber) {
        LambdaUpdateWrapper<WinderTime> uw = new LambdaUpdateWrapper<WinderTime>()
                .set(WinderTime::getBurstTime, time)
                .set(WinderTime::getVariety,variety)
                .set(WinderTime::getModelNumber,modelNumber)
                .eq(WinderTime::getId, id);
        winderTimeMapper.update(null, uw);
    }
    /**
     * 查询所有的卷绕机络筒后停留时间
     *
     * @return
     */
    public List<WinderTime> listWinder() {
        return new LambdaQueryChainWrapper<>(winderTimeMapper)
                .list();
    }
    /**
     * 查询所有的卷绕机络筒后停留时间
     *
     * @return
     */
    public List<WinderTime> blurListWinder(String winderName) {
        return new LambdaQueryChainWrapper<>(winderTimeMapper)
                .like(WinderTime::getWinderName,winderName)
                .list();
    }

    /**
     * 根据线号纺丝位号查询该位络筒后停留时间
     *
     */
    public Long getInputTaskTime(Integer winderLine, Integer taskWinderSpinningCode) {
        WinderTime winderTime = new LambdaQueryChainWrapper<>(winderTimeMapper)
                .eq(WinderTime::getWinderLine, winderLine)
                .eq(WinderTime::getWinderSpinningCode, taskWinderSpinningCode)
                .one();
       return winderTime.getBurstTime();
    }
}
